package f.admin.entity;

import java.lang.reflect.Field;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class BusinessObject {

	private String id;
	private String name;
	private String aliasName;
	private String tableName;
	private BusinessModule businessModule;
	private String businessModuleName;
	private Date createTime;
	private Map<String, BusinessProperty> properties;
	
	protected String getId() {
		return id;
	}
	protected void setId(String id) {
		this.id = id;
	}
	protected String getName() {
		return name;
	}
	protected void setName(String name) {
		this.name = name;
	}
	protected String getAliasName() {
		return aliasName;
	}
	protected void setAliasName(String aliasName) {
		this.aliasName = aliasName;
	}
	protected String getTableName() {
		return tableName;
	}
	protected void setTableName(String tableName) {
		this.tableName = tableName;
	}
	protected BusinessModule getBusinessModule() {
		return businessModule;
	}
	protected void setBusinessModule(BusinessModule businessModule) {
		this.businessModule = businessModule;
	}
	protected String getBusinessModuleName() {
		return businessModuleName;
	}
	protected void setBusinessModuleName(String businessModuleName) {
		this.businessModuleName = businessModuleName;
	}
	protected Date getCreateTime() {
		return createTime;
	}
	protected void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	protected Map<String, BusinessProperty> getProperties() {
		return properties;
	}
	protected void setProperties(Map<String, BusinessProperty> properties) {
		this.properties = properties;
	}
	
	public String getJsonString() {
		JSONObject jsonObj = new JSONObject();
		Field[] fields = this.getClass().getFields();
		for(int i = 0; i < fields.length; i++) {
			Field field = fields[i];
			try {
				/*Object fieldValue = field.get(this);
				if(fieldValue instanceof Map) {
					JSONArray jsonArr = new JSONArray();
					Map<String, BusinessProperty> propertyMap = (Map<String, BusinessProperty>) fieldValue;
					Iterator<String> its = propertyMap.keySet().iterator();
					while(its.hasNext()) {
						String propertyName = its.next();
						BusinessProperty property = propertyMap.get(propertyName);
						String property = 
					}
				} else {
					jsonObj.put(field.getName(), field.get(this));
				}*/
				jsonObj.put(field.getName(), field.get(this));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return jsonObj.toString();
	}
}
